<template>
	<view class="content">
		<view class="user-info" @click="jump('/pages/login/login')">
			<view class="user-tx">
				<image :src="info.avatar || 'https://s1.ax1x.com/2022/11/18/znVZIP.png'" mode=""></image>
			</view>
			<view class="user-name">
				<text class="name">{{info.nickname || '请登录~'}}</text>
				<text class="phone">手机号：{{info.mobile || ''}}</text>
			</view>
			<image class="user-info-bg" style="width: 115rpx;height: 115rpx;" src="https://s1.ax1x.com/2022/11/18/znVVat.png" mode=""></image>
		</view>
		<!-- 我的订单 -->
		<view class="my-order">
			<view class="my-title-box">
				<view class="my-title">报修订单</view>
				<view class="more" @click="jump('/pages/user/order/order?user_status=-1')">查看全部
					<image style="width: 12rpx;height: 21rpx;margin-left: 13rpx;" src="https://s1.ax1x.com/2022/11/18/znVmPf.png" mode=""></image>
				</view>
			</view>
			<view class="my-order-list">
				<view class="my-order-li" @click="jump('/pages/user/order/order?user_status=0')">
					<view class="image" style="width: 42rpx;height: 42rpx;">
						<u-badge size="mini" type="error" :count="orderNum[0].num" :is-center="true"></u-badge>
						<image src="https://s1.ax1x.com/2022/11/18/znVFrd.png" mode=""></image>
					</view>
					<text>已提交</text>
				</view>
				<view class="my-order-li" @click="jump('/pages/user/order/order?user_status=1')">
					<view class="image" style="width: 42rpx;height: 42rpx;">
						<u-badge size="mini" type="error" :count="orderNum[1].num" :is-center="true"></u-badge>
						<image src="https://s1.ax1x.com/2022/11/18/znViKH.png" mode=""></image>
					</view>
					<text>维修中</text>
				</view>
				<view class="my-order-li" @click="jump('/pages/user/order/order?user_status=2')">
					<view class="image" style="width: 46rpx;height: 42rpx;">
						<u-badge size="mini" type="error" :count="orderNum[2].num" :is-center="true"></u-badge>
						<image src="https://s1.ax1x.com/2022/11/18/znVEVI.png" mode=""></image>
					</view>
					<text>待确认</text>
				</view>
				<view class="my-order-li" @click="jump('/pages/user/order/order?user_status=3')">
					<view class="image" style="width: 38rpx;height: 43rpx;">
						<u-badge size="mini" type="error" :count="orderNum[3].num" :is-center="true"></u-badge>
						<image src="https://s1.ax1x.com/2022/11/18/znVkqA.png" mode=""></image>
					</view>
					<text>已完成</text>
				</view>
			</view>
		</view>
		<!-- 其他功能 -->
		<view class="gongnneg">
			<view class="my-title-box">
				<view class="my-title">其他功能</view>
				<!-- <view class="more">查看全部</view> -->
			</view>
			<!-- <view class="gongnneg-li" style="margin-top: 40rpx;" @click="jump('/pages/service/index/index')">
				<view class="gongnneg-left">
					<image style="width: 32rpx;height: 35rpx;" src="https://s1.ax1x.com/2022/11/18/znsFVH.png" mode=""></image>
					<text>服务商</text>
				</view>
				<view class="gongnneg-right">
					<image style="width: 10rpx;height: 18rpx;" src="https://s1.ax1x.com/2022/11/18/znVCxe.png" mode=""></image>
				</view>
			</view> -->
			<view class="gongnneg-li" style="margin-top: 40rpx;" @click="jump('/pages/personal/personal')">
				<view class="gongnneg-left">
					<image style="width: 32rpx;height: 35rpx;" src="https://s1.ax1x.com/2022/11/18/znsFVH.png" mode=""></image>
					<text>基本资料</text>
				</view>
				<view class="gongnneg-right">
					<image style="width: 10rpx;height: 18rpx;" src="https://s1.ax1x.com/2022/11/18/znVCxe.png" mode=""></image>
				</view>
			</view>
			<view class="gongnneg-li"  @click="jump('/pages/about/about')">
				<view class="gongnneg-left">
					<image style="width: 32rpx;height: 35rpx;" src="https://s1.ax1x.com/2022/11/18/znsFVH.png" mode=""></image>
					<text>关于我们</text>
				</view>
				<view class="gongnneg-right">
					<image style="width: 10rpx;height: 18rpx;" src="https://s1.ax1x.com/2022/11/18/znVCxe.png" mode=""></image>
				</view>
			</view>
			<view class="gongnneg-li" @click="jump('/pages/feedback/feedback')">
				<view class="gongnneg-left">
					<image style="width: 32rpx;height: 35rpx;" src="https://s1.ax1x.com/2022/11/18/znsPqe.png" mode=""></image>
					<text>意见反馈</text>
				</view>
				<view class="gongnneg-right">
					<image style="width: 10rpx;height: 18rpx;" src="https://s1.ax1x.com/2022/11/18/znVCxe.png" mode=""></image>
				</view>
			</view>
			<button class="gongnneg-li u-reset-button" open-type="contact">
				<view class="gongnneg-left">
					<image style="width: 32rpx;height: 35rpx;" src="https://s1.ax1x.com/2022/11/18/znsCrD.png" mode=""></image>
					<text>在线客服</text>
				</view>
				<view class="gongnneg-right">
					<image style="width: 10rpx;height: 18rpx;" src="https://s1.ax1x.com/2022/11/18/znVCxe.png" mode=""></image>
				</view>
			</button> 
		</view>
		<!-- 退出登陆 -->
		<button class="u-reset-button btn1" v-if="info.avatar" @click="outLogin()">退出登录</button>
		
		
		<u-tabbar :list="tabbar" height='130rpx' active-color='#0055B0' inactive-color='#7F8699'></u-tabbar>
		<u-modal v-model="show" :content="content" :confirm-text="confirm_text" show-cancel-button cancel-text="取消" @confirm="qdinfo()"></u-modal>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				info:[],
				orderNum:[
					{num:0},
					{num:0},
					{num:0},
					{num:0},
				],
				tabbar: '',
				show:false,//弹窗
				content:'您未完善身份信息',
				confirm_text:"去完善",
			}
		},
		onLoad(){
			this.tabbar = [
				{
					iconPath: "/static/home.png",
					selectedIconPath: "static/home-a.png",
					text: '首页',
					pagePath: "/pages/user/index/index"
				},
				{
					iconPath: "/static/my.png",
					selectedIconPath: "/static/my-a.png",
					text: '我的',
					pagePath: "/pages/user/my/my"
				}
			]
			this.checkinfo()
			
		},
		onShow() {
			if(uni.getStorageSync('userId')){
				
				this.getUserInfo()
				this.getOrderNum()
			}else{
				this.info = []
				this.orderNum = [
					{num:0},
					{num:0},
					{num:0},
					{num:0},
				]
				
			}
			
		},
		methods: {
			//判断是否完善身份信息
			checkinfo(){
				if(uni.getStorageSync('userId')){
					this.$u.post('index/checkbasic',{}).then(res =>{	
						if(res.data.status==1){
							this.checkdingdan()
						}else{
							this.show = true		
						}
										
						
					})
				}
			},
			qdinfo(){
				if(this.confirm_text == "去完善"){
					uni.navigateTo({
						url:'/pages/personal/personal'
					})
					return
				}
				if(this.confirm_text == "去确定"){
					uni.navigateTo({
						url:'/pages/user/order/order?user_status=2'
					})
					return
				}
				
			},
			//判断是否有待确认的订单
			checkdingdan(){	
					this.$u.post('index/check_order',{}).then(res =>{
						//console.log(res)
						if(res.data.count == 0){
							//console.log('已确认')
							return
						}
						//console.log('去确认')
						this.content = "您有  "+res.data.count+"  个待确认订单，请尽快确认"
						this.confirm_text = "去确定"
						this.show = true							
						
					})
			},
			clcikNavigator(item,index){
				if(uni.getStorageSync('userId')){
					uni.navigateTo({
						url:'/pages/user/register/register?id='+item.id+'&index='+index+'&name='+item.name
					})
				}else{
					uni.navigateTo({
						url:'../../login/login'
					})
				}
				
			},
			jump(url){
				//console.log(111)
				if(uni.getStorageSync('userId')){
					if(url == '/pages/login/login'){
						return
					}
					uni.navigateTo({
						url:url
					})
				}else{
					if(url == '/pages/login/login'){
						uni.navigateTo({
							url:url
						})
						return
					}
					uni.showModal({
						title: '温馨提示',
						content: '请先登录',
						success: function (res) {
							if (res.confirm) {
								uni.navigateTo({
									url:'../../login/login'
								})
							} else if (res.cancel) {
								uni.switchTab({
									url:'/pages/user/index/index'
								})
							}
						}
					});
				}
			},
			//  获取用户信息
			getUserInfo(){
				this.$u.post('/index/userinfo',{}).then(res =>{
					this.info = res.data
					
				})
			},
			//  获取订单数量
			getOrderNum(){
				this.$u.post('/index/order_list',{}).then(res =>{
					// console.log(res)
					this.orderNum = res.data
				})
			},
			// 退出登录
			outLogin(){
				uni.showModal({
					title: '温馨提示',
					content: '确定要退出登录吗？',
					success: function (res) {
						if (res.confirm) {
							uni.showToast({
								icon:'success',
								title:'退出成功'
							})
							uni.removeStorageSync('userId')
							setTimeout(()=>{
								uni.switchTab({
									url:'/pages/user/index/index'
								})
							},800)
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
		}
	}
</script>

<style lang="less">
	.u-tabbar__content{
		height: 69rpx;
	}
	.u-tabbar__content__item__text{
			font-size: 39rpx !important;
		}
	.u-icon__img{
			width: 72rpx !important;
			height: 63rpx !important;
		}
.content{
	background-image: linear-gradient(0deg, #0055B0 0%, #0184D0 100%);
	background-repeat: no-repeat;
	background-size: 100% 246rpx;
	padding-bottom: 100rpx;
}
.user-info{
	position: relative;
	height: 220rpx;
	display: flex;
	// align-items: center;
	padding-top: 38rpx;
	padding-left: 37rpx;
	box-sizing: border-box;
	.user-tx{
		width: 128rpx;
		height: 128rpx;
		border-radius: 50%;
		overflow: hidden;
		margin-right: 33rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		background: #fff;
		border: 4rpx solid rgba(255, 255, 255, 0.42);
		image{
			width: 106rpx;
			height: 106rpx;
		}
	}
	.user-name{
		display: flex;
		flex-direction: column;
		margin-top: 12rpx;
		.name{
			font-size: 42rpx;
			font-weight: bold;
			color: #fff;
			margin-bottom: 9rpx;
		}
		.phone{
			font-size: 32rpx;
			color: #F6F6F6;
		}
	}
}
.user-info-bg{
	position: absolute;
	right: -20rpx;
	bottom: 2rpx;
}
.my-order{
	background: #fff;
	border-radius: 0px 0px 10rpx 10rpx;
	margin-top: 22rpx;
	padding-top: 40rpx;
}
.my-title-box{
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 0 30rpx;
	position: relative;
	overflow: hidden;
	.my-title{
		font-weight: 800;
		font-size: 44rpx;
		display: flex;
		align-items: center;
		&::after{
			content: "";
			width: 20rpx;
			height: 20rpx;
			border-radius: 50%;
			position: absolute;
			left: -10rpx;
			background: #0055B0;
		}
	}
	.more{
		font-size: 30rpx;
		color: #999999;
	}
}
.my-order-list{
	padding: 0 30rpx;
	display: flex;
	justify-content: space-between;
	margin-top: 51rpx;
	padding-bottom: 40rpx;
}
.my-order-li{
	display: flex;
	flex-direction: column;
	justify-items: center;
	align-items: center;
	.image{
		position: relative;
		margin-bottom: 22rpx;
		width: 60rpx !important;
		height: 57rpx !important;
	}
	image{
		width: 100%;
		height: 100%;
	}
	text{
		font-size: 38rpx;
		color: #646464;
	}
}
.gongnneg{
	background: #fff;
	margin-top: 20rpx;	
	border-radius: 10rpx;
	padding-top: 40rpx;
}
.gongnneg-li{
	padding: 0 10rpx;
	border-top: 1px solid #EEEEEE;
	display: flex;
	align-items: center;
	justify-content: space-between;
	height: 98rpx;
}
.gongnneg-left{
	display: flex;
	align-items: center;
	justify-content: space-between;
	image{
		margin-right: 13rpx;
		    width: 23px !important;
		    height: 22px !important;
	}
	text{
		font-size:38rpx;
	}
}
.gongnneg-right{

	image{
		        width: 9px !important;
		        height: 13px !important;
	}
}

.btn1{
	width: 650rpx;
	height: 103rpx;
	background: #0055B0;
	border-radius: 40rpx;
	margin: 0 auto;
	margin-top: 79rpx;
	display: flex;
	align-items: center;
	justify-content: center;
	color: #FFFFFF;
	font-size: 42rpx;
}
</style>
